package com.twq.types.typeximplicit

/**
 * Created by tangweiqun on 2017/11/20.
 */
trait SpecializedMethod[T] {
  def compress(implicit ev: T =:= Int) = println("compress")
}


object SpecializedMethod {
  def main(args: Array[String]): Unit = {
    //1、利用隐式参数来达到对方法做限定
    val list = List(1, 2, 5)
    println(list.sum)

    implicit object StringNumeric extends Numeric[String] {
      override def zero: String = ""

      override def plus(x: String, y: String): String = x + y

      override def minus(x: String, y: String): String = ???

      override def times(x: String, y: String): String = ???

      override def negate(x: String): String = ???

      override def fromInt(x: Int): String = ???

      override def toInt(x: String): Int = ???

      override def toLong(x: String): Long = ???

      override def toFloat(x: String): Float = ???

      override def toDouble(x: String): Double = ???

      override def compare(x: String, y: String): Int = ???
    }

    val strList = List("one", "true", "three")
    println(strList.sum)

    //2、利用 =:= 来对方法做限定
    val set = new SpecializedMethod[Int] {}
    set.compress

    val strSet = new SpecializedMethod[String] {}
    //strSet.compress
  }
}

